package com.fanxuankai.boot.generator;

import cn.hutool.core.text.StrPool;
import com.fanxuankai.boot.generator.autoconfigure.CodeGeneratorProperties;
import com.fanxuankai.boot.generator.service.GeneratorService;
import com.fanxuankai.commons.util.OptionalUtils;

/**
 * @author fanxuankai
 */
public class CodeGenerator {
    private final GeneratorService generatorService;
    private final CodeGeneratorProperties generatorProperties;

    public CodeGenerator(GeneratorService generatorService, CodeGeneratorProperties generatorProperties) {
        this.generatorService = generatorService;
        this.generatorProperties = generatorProperties;
    }

    /**
     * 生成代码
     */
    public void generate() {
        OptionalUtils.ofNullable(generatorProperties.getTables())
                .ifPresent(tables -> {
                    for (String file : tables.split(StrPool.COMMA)) {
                        generatorService.generateCode(file);
                    }
                });
    }
}
